package handler.commandprocessor;

import dao.ClientDAO;
import handler.CommandHandler;
import io.netty.channel.ChannelHandlerContext;
import message.Command;
import message.command.SendToClientCommand;
import route.Router;

public class SendToClientProcessor implements CommandHandler.CommandProcessor
{

    private ClientDAO clientDAO;
    private Router    router;

    public SendToClientProcessor(ClientDAO clientDAO, Router router)
    {
        this.clientDAO = clientDAO;
        this.router = router;
    }

    @Override
    public void process(Command command, ChannelHandlerContext ctx)
    {
        String clientName = ((SendToClientCommand) command).getClientName();
        String msg        = ((SendToClientCommand) command).getMsg();
        String clientId   = clientDAO.find(clientName);
        router.sendToClient(clientId, msg);
    }
}
